package io.github.uicdb.et.item.curios;

import com.google.common.collect.Multimap;
import io.github.uicdb.et.ModAttributes;
import io.github.uicdb.et.ModElements;
import net.minecraft.ChatFormatting;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.ItemStack;
import top.theillusivec4.curios.api.SlotContext;

import java.util.List;

public class WheatWaveItem extends CurioItem {
    public WheatWaveItem(Properties properties) {
        super(properties, 0);
    }

    @Override
    public void appendDefaultAttribute(Multimap<Holder<Attribute>, AttributeModifier> map, SlotContext slotContext, ResourceLocation id, ItemStack stack) {
        map.put(ModAttributes.HEALTH_RECOVERY, getSlotModifier(0, slotContext, 1, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));
        map.put(Attributes.ATTACK_DAMAGE, getSlotModifier(1, slotContext, 1, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));
        map.put(Attributes.ARMOR, getSlotModifier(2, slotContext, 1, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));
        map.put(Attributes.MAX_HEALTH, getSlotModifier(3, slotContext, 1, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));
    }

    @Override
    public void onEquip(SlotContext slotContext, ItemStack prevStack, ItemStack stack) {
        super.onEquip(slotContext, prevStack, stack);
        if (slotContext.entity().getRandom().nextFloat() < 0.75f) {
            //装备时75%概率自杀,死于光元素
            slotContext.entity().hurt(ModElements.YANG.getElemental().getDamageSource(slotContext.entity().level(), slotContext.entity()),1.5f* ModAttributes.safeGet(Attributes.MAX_HEALTH, slotContext.entity()));
        }
    }

    @Override
    public void addAdditionTooltip(List<Component> tooltips, ItemStack stack) {
        tooltips.add(translate("wheat_wave.0").withStyle(ChatFormatting.LIGHT_PURPLE));
        tooltips.add(translate("wheat_wave.1").withStyle(ChatFormatting.RED));
    }
}
